package net.csdn.business.notify.handler.utils;



import net.csdn.business.notify.common.enums.NotifyChannel;
import net.csdn.business.notify.common.enums.NotifyType;
import net.csdn.business.notify.common.pipeline.domain.TaskInfo;

import java.util.ArrayList;
import java.util.List;



/**
 * @ClassName GroupIdMappingUtils
 * @Description groupId 标识着每一个消费者组
 * @Author zhangyl
 * @Date 2023/11/30 14:55
 */
public class GroupIdMappingUtils {

    /**
     * 获取所有的groupIds
     * (不同的渠道不同的消息类型拥有自己的groupId)
     */
    public static List<String> getAllGroupIds() {
        List<String> groupIds = new ArrayList<>();
        for (NotifyChannel notifyChannel : NotifyChannel.values()) {
            for (NotifyType notifyType : NotifyType.values()) {
                groupIds.add(notifyChannel.getCodeEn() + "-" + notifyType.getCodeEn());
            }
        }
        return groupIds;
    }


    /**
     * 根据TaskInfo获取当前消息的groupId
     *
     * @param taskInfo
     * @return
     */
    public static String getGroupIdByTaskInfo(TaskInfo taskInfo) {
        String channelCodeEn = NotifyChannel.ofCodeEn(taskInfo.getNotifyChannel());
        String msgCodeEn = NotifyType.ofCodeEn(taskInfo.getNotifyType());
        return channelCodeEn + "-" + msgCodeEn;
    }
}
